home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / muzsrc1.zip / PRINT.CPP < prev    next >
C/C++ Source or Header  |  1992-07-21  |  5KB  |  161 lines

  1. // **********************************************
  2. // File: PRINT.CPP
  3. // Printing functions
  4.  
  5. #include "muzika.h"
  6. #include <string.h>
  7. #include <values.h>
  8.  
  9. // **********************************************
  10. // PrintSinglePart dumps the given part to a printer device context.
  11.  
  12. void PrintSinglePart(HDC hPrinterDC, int part)
  13. {
  14.   // Print a single part
  15.   Part &p = *((Part *) &melody.part[part]);
  16.   Escape(hPrinterDC, STARTDOC, strlen(programTitle), programTitle, NULL);
  17.   Escape(hPrinterDC, NEWFRAME, NULL, NULL, NULL);
  18.  
  19.   // Draw the staves in the device context
  20.   for (int index = 0; index < p.staff.number(); ++index) {
  21.     Staff &s = *((Staff *) &p.staff[index]);
  22.  
  23.     int firstY, lastY, relY;
  24.     if (index % p.multiplicity() == 0) {
  25.       firstY = -1;
  26.       lastY = MAXINT-24;
  27.       relY = s.Y()-pixelsPerStaff;
  28.     }
  29.  
  30.     // Draw the staff itself
  31.     s.Draw(hPrinterDC, relY, FALSE);
  32.     staffX = s.X();
  33.     staffY = s.Y()-relY;
  34.  
  35.     // Check whether first or last staff in a group
  36.     staffLoc = MIDSTAFF;
  37.     if (index % p.multiplicity() == 0) {
  38.       firstY = staffY;
  39.       staffLoc = FIRSTSTAFF;
  40.     }
  41.     if ((index+1) % p.multiplicity() == 0) {
  42.       lastY = staffY;
  43.       staffLoc = LASTSTAFF;
  44.     }
  45.     if (p.multiplicity() == 1)
  46.       staffLoc = SINGLESTAFF;
  47.     currStaffHeight = (index+1 < p.staff.number()) ?
  48.       ((Staff *) &p.staff[index+1])->Y()-s.Y() : pixelsPerStaff;
  49.  
  50.     // Draw the point objects inside the staff
  51.     IndexedList &pointList = s.pointObject;
  52.     for (int i = 0; i < pointList.number(); ++i)
  53.       ((PointObject *) &pointList[i])->Draw(hPrinterDC);
  54.  
  55.     // Draw the continuous objects inside the staff
  56.     IndexedList &contList = s.continuousObject;
  57.     for (i = 0; i < contList.number(); ++i)
  58.       ((ContinuousObject *) &contList[i])->Draw(hPrinterDC);
  59.  
  60.     if ((index+1)%p.multiplicity() == 0) {
  61.       // Draw the connecting lines of a multiple staff
  62.       MoveTo(hPrinterDC, s.X(), firstY);
  63.       LineTo(hPrinterDC, s.X(), lastY+24);
  64.       MoveTo(hPrinterDC, s.X()+s.width()-1, firstY);
  65.       LineTo(hPrinterDC, s.X()+s.width()-1, lastY+24);
  66.  
  67.       // Dump the staff to the printer
  68.       Escape(hPrinterDC, NEXTBAND, NULL, NULL, NULL);
  69.     }
  70.   }
  71.   Escape(hPrinterDC, ENDDOC, NULL, NULL, NULL);
  72. }
  73.  
  74. // **********************************************
  75. // PrintScore makes a hard copy of an entire score.
  76.  
  77. void PrintScore(HDC hPrinterDC)
  78. {
  79.   int line = 0;
  80.   int staffLeftX = 32;
  81.   int staffRightX = 32+melody.GetStaffWidth();
  82.  
  83.   Escape(hPrinterDC, STARTDOC, strlen(programTitle), programTitle, NULL);
  84.   Escape(hPrinterDC, NEWFRAME, NULL, NULL, NULL);
  85.  
  86.   for (int scoreIndex = 0; scoreIndex < scoreStaves; ++scoreIndex) {
  87.     // Print a multiple staff
  88.     for (int partIndex = 0; partIndex < melody.part.number();
  89.       ++partIndex) {
  90.       Part &p = *((Part *) &melody.part[partIndex]);
  91.       for (int staffIndex = scoreIndex*p.multiplicity();
  92.         staffIndex < (scoreIndex+1)*p.multiplicity(); ++staffIndex) {
  93.         // Draw a single staff
  94.         Staff &s = *((Staff *) &p.staff[staffIndex]);
  95.         int tempY = s.Y();
  96.         s.Y() = line += pixelsPerStaff;
  97.         s.Draw(hPrinterDC, 0, FALSE);
  98.         staffX = staffLeftX;
  99.         staffY = line;
  100.  
  101.         // Draw the point objects inside the staff
  102.         IndexedList &pointList = s.pointObject;
  103.         for (int i = 0; i < pointList.number(); ++i)
  104.           ((PointObject *) &pointList[i])->Draw(hPrinterDC);
  105.  
  106.         // Draw the continuous objects inside the staff
  107.         IndexedList &contList = s.continuousObject;
  108.         for (i = 0; i < contList.number(); ++i)
  109.           ((ContinuousObject *) &contList[i])->Draw(hPrinterDC);
  110.  
  111.         s.Y() = tempY;
  112.       }
  113.     }
  114.  
  115.     // Draw the connecting lines of the score multiple staff
  116.     MoveTo(hPrinterDC, staffLeftX,
  117.       line-(scoreMultiplicity-1)*pixelsPerStaff);
  118.     LineTo(hPrinterDC, staffLeftX, line+24);
  119.     MoveTo(hPrinterDC, staffRightX,
  120.       line-(scoreMultiplicity-1)*pixelsPerStaff);
  121.     LineTo(hPrinterDC, staffRightX, line+24);
  122.  
  123.     // Dump the multiple staff to printer
  124.     Escape(hPrinterDC, NEXTBAND, NULL, NULL, NULL);
  125.   }
  126.  
  127.   Escape(hPrinterDC, ENDDOC, NULL, NULL, NULL);
  128. }
  129.  
  130. // **********************************************
  131. // PrintEditWindow creates a printer device context
  132. // and calls either PrintSinglePart or PrintScore according
  133. // to the current edit window display settings.
  134.  
  135. void PrintEditWindow()
  136. {
  137.   char pPrintInfo[80];
  138.   LPSTR lpPrintType, lpPrintDriver, lpPrintPort;
  139.  
  140.   // Create a printer device context
  141.   if (!GetProfileString("windows", "device", "", pPrintInfo, 80)) {
  142.     MessageBox(hMainWnd, "Your system does not have a printer installed.", NULL,
  143.       MB_ICONSTOP | MB_OK);
  144.     return;
  145.   }
  146.  
  147.   lpPrintType = pPrintInfo;
  148.   lpPrintDriver = _fstrstr(pPrintInfo, ",");
  149.   *lpPrintDriver++ = 0;
  150.   lpPrintPort = _fstrstr(lpPrintDriver, ",");
  151.   *lpPrintPort++ = 0;
  152.   HDC hPrinterDC = CreateDC(lpPrintDriver, lpPrintType, lpPrintPort, NULL);
  153.  
  154.   if (!scoreDisplay)
  155.     PrintSinglePart(hPrinterDC, displayedPart);
  156.   else
  157.     PrintScore(hPrinterDC);
  158.  
  159.   DeleteDC(hPrinterDC);
  160. }
  161.